<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveModel::SecurePassword::ClassMethods::InstanceMethodsOnActivation</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveModel::SecurePassword::ClassMethods::InstanceMethodsOnActivation 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../../files/activemodel/lib/active_model/secure_password_rb.html">activemodel/lib/active_model/secure_password.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="InstanceMethodsOnActivation.html#method-i-authenticate">authenticate</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>P</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="InstanceMethodsOnActivation.html#method-i-password-3D">password=</a>,
              </li>
            
              
              <li>
                <a href="InstanceMethodsOnActivation.html#method-i-password_confirmation-3D">password_confirmation=</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-authenticate">
            
              <b>authenticate</b>(unencrypted_password)
            
            <a href="InstanceMethodsOnActivation.html#method-i-authenticate" name="method-i-authenticate" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Returns <code>self</code> if the password is correct, otherwise
<code>false</code>.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">User</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_secure_password</span> <span class="ruby-identifier">validations</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span><span class="ruby-operator">:</span> <span class="ruby-string">'david'</span>, <span class="ruby-identifier">password</span><span class="ruby-operator">:</span> <span class="ruby-string">'mUc3m00RsqyRe'</span>)
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">save</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-string">'notright'</span>)      <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-string">'mUc3m00RsqyRe'</span>) <span class="ruby-comment"># =&gt; user</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-authenticate_source')" id="l_method-i-authenticate_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b965ce361b89ad33a4a4b422f8e564233926c723/activemodel/lib/active_model/secure_password.rb#L85" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-authenticate_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activemodel/lib/active_model/secure_password.rb, line 85</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">authenticate</span>(<span class="ruby-identifier">unencrypted_password</span>)
  <span class="ruby-constant">BCrypt</span><span class="ruby-operator">::</span><span class="ruby-constant">Password</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">password_digest</span>) <span class="ruby-operator">==</span> <span class="ruby-identifier">unencrypted_password</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-password-3D">
            
              <b>password=</b>(unencrypted_password)
            
            <a href="InstanceMethodsOnActivation.html#method-i-password-3D" name="method-i-password-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Encrypts the password into the <code>password_digest</code> attribute, only
if the new password is not blank.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">User</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">has_secure_password</span> <span class="ruby-identifier">validations</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">password</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">password_digest</span> <span class="ruby-comment"># =&gt; nil</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">password</span> = <span class="ruby-string">'mUc3m00RsqyRe'</span>
<span class="ruby-identifier">user</span>.<span class="ruby-identifier">password_digest</span> <span class="ruby-comment"># =&gt; &quot;$2a$10$4LEA7r4YmNHtvlAvHhsYAeZmk/xeUVtMTYqwIvYY76EW5GUqDiP4.&quot;</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-password-3D_source')" id="l_method-i-password-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b965ce361b89ad33a4a4b422f8e564233926c723/activemodel/lib/active_model/secure_password.rb#L101" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-password-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activemodel/lib/active_model/secure_password.rb, line 101</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">password=</span>(<span class="ruby-identifier">unencrypted_password</span>)
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">unencrypted_password</span>.<span class="ruby-identifier">blank?</span>
    <span class="ruby-ivar">@password</span> = <span class="ruby-identifier">unencrypted_password</span>
    <span class="ruby-identifier">cost</span> = <span class="ruby-constant">ActiveModel</span><span class="ruby-operator">::</span><span class="ruby-constant">SecurePassword</span>.<span class="ruby-identifier">min_cost</span> <span class="ruby-operator">?</span> <span class="ruby-constant">BCrypt</span><span class="ruby-operator">::</span><span class="ruby-constant">Engine</span><span class="ruby-operator">::</span><span class="ruby-constant">MIN_COST</span> <span class="ruby-operator">:</span> <span class="ruby-constant">BCrypt</span><span class="ruby-operator">::</span><span class="ruby-constant">Engine</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_COST</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">password_digest</span> = <span class="ruby-constant">BCrypt</span><span class="ruby-operator">::</span><span class="ruby-constant">Password</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">unencrypted_password</span>, <span class="ruby-identifier">cost</span><span class="ruby-operator">:</span> <span class="ruby-identifier">cost</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-password_confirmation-3D">
            
              <b>password_confirmation=</b>(unencrypted_password)
            
            <a href="InstanceMethodsOnActivation.html#method-i-password_confirmation-3D" name="method-i-password_confirmation-3D" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-password_confirmation-3D_source')" id="l_method-i-password_confirmation-3D_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/b965ce361b89ad33a4a4b422f8e564233926c723/activemodel/lib/active_model/secure_password.rb#L109" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-password_confirmation-3D_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activemodel/lib/active_model/secure_password.rb, line 109</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">password_confirmation=</span>(<span class="ruby-identifier">unencrypted_password</span>)
  <span class="ruby-ivar">@password_confirmation</span> = <span class="ruby-identifier">unencrypted_password</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    